#ifndef THINK_THINK_LANG_H
#define THINK_THINK_LANG_H

static char* think_lang =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace think;\n"
	"\n"
	"class Lang\n"
	"{\n"
	"    /**\n"
	"     * @var array 语言数据\n"
	"     */\n"
	"    private static $lang = [];\n"
	"\n"
	"    /**\n"
	"     * @var string 语言作用域\n"
	"     */\n"
	"    private static $range = \'zh-cn\';\n"
	"\n"
	"    /**\n"
	"     * @var string 语言自动侦测的变量\n"
	"     */\n"
	"    protected static $langDetectVar = \'lang\';\n"
	"\n"
	"    /**\n"
	"     * @var string 语言 Cookie 变量\n"
	"     */\n"
	"    protected static $langCookieVar = \'think_var\';\n"
	"\n"
	"    /**\n"
	"     * @var int 语言 Cookie 的过期时间\n"
	"     */\n"
	"    protected static $langCookieExpire = 3600;\n"
	"\n"
	"    /**\n"
	"     * @var array 允许语言列表\n"
	"     */\n"
	"    protected static $allowLangList = [];\n"
	"\n"
	"    /**\n"
	"     * @var array Accept-Language 转义为对应语言包名称 系统默认配置\n"
	"     */\n"
	"    protected static $acceptLanguage = [\'zh-hans-cn\' => \'zh-cn\'];\n"
	"\n"
	"    /**\n"
	"     * 设定当前的语言\n"
	"     * @access public\n"
	"     * @param  string $range 语言作用域\n"
	"     * @return string\n"
	"     */\n"
	"    public static function range($range = \'\')\n"
	"    {\n"
	"        if ($range) {\n"
	"            self::$range = $range;\n"
	"        }\n"
	"\n"
	"        return self::$range;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置语言定义(不区分大小写)\n"
	"     * @access public\n"
	"     * @param  string|array  $name  语言变量\n"
	"     * @param  string        $value 语言值\n"
	"     * @param  string        $range 语言作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function set($name, $value = null, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        if (!isset(self::$lang[$range])) {\n"
	"            self::$lang[$range] = [];\n"
	"        }\n"
	"\n"
	"        if (is_array($name)) {\n"
	"            return self::$lang[$range] = array_change_key_case($name) + self::$lang[$range];\n"
	"        }\n"
	"\n"
	"        return self::$lang[$range][strtolower($name)] = $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 加载语言定义(不区分大小写)\n"
	"     * @access public\n"
	"     * @param  array|string $file 语言文件\n"
	"     * @param  string $range      语言作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function load($file, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"        $file  = is_string($file) ? [$file] : $file;\n"
	"\n"
	"        if (!isset(self::$lang[$range])) {\n"
	"            self::$lang[$range] = [];\n"
	"        }\n"
	"\n"
	"        $lang = [];\n"
	"\n"
	"        foreach ($file as $_file) {\n"
	"            if (is_file($_file)) {\n"
	"                // 记录加载信息\n"
	"                App::$debug && Log::record(\'[ LANG ] \' . $_file, \'info\');\n"
	"\n"
	"                $_lang = include $_file;\n"
	"\n"
	"                if (is_array($_lang)) {\n"
	"                    $lang = array_change_key_case($_lang) + $lang;\n"
	"                }\n"
	"            }\n"
	"        }\n"
	"\n"
	"        if (!empty($lang)) {\n"
	"            self::$lang[$range] = $lang + self::$lang[$range];\n"
	"        }\n"
	"\n"
	"        return self::$lang[$range];\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取语言定义(不区分大小写)\n"
	"     * @access public\n"
	"     * @param  string|null $name  语言变量\n"
	"     * @param  string      $range 语言作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function has($name, $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        return isset(self::$lang[$range][strtolower($name)]);\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 获取语言定义(不区分大小写)\n"
	"     * @access public\n"
	"     * @param  string|null $name  语言变量\n"
	"     * @param  array       $vars  变量替换\n"
	"     * @param  string      $range 语言作用域\n"
	"     * @return mixed\n"
	"     */\n"
	"    public static function get($name = null, $vars = [], $range = \'\')\n"
	"    {\n"
	"        $range = $range ?: self::$range;\n"
	"\n"
	"        // 空参数返回所有定义\n"
	"        if (empty($name)) {\n"
	"            return self::$lang[$range];\n"
	"        }\n"
	"\n"
	"        $key   = strtolower($name);\n"
	"        $value = isset(self::$lang[$range][$key]) ? self::$lang[$range][$key] : $name;\n"
	"\n"
	"        // 变量解析\n"
	"        if (!empty($vars) && is_array($vars)) {\n"
	"            /**\n"
	"             * Notes:\n"
	"             * 为了检测的方便，数字索引的判断仅仅是参数数组的第一个元素的key为数字0\n"
	"             * 数字索引采用的是系统的 sprintf 函数替换，用法请参考 sprintf 函数\n"
	"             */\n"
	"            if (key($vars) === 0) {\n"
	"                // 数字索引解析\n"
	"                array_unshift($vars, $value);\n"
	"                $value = call_user_func_array(\'sprintf\', $vars);\n"
	"            } else {\n"
	"                // 关联索引解析\n"
	"                $replace = array_keys($vars);\n"
	"                foreach ($replace as &$v) {\n"
	"                    $v = \"{:{$v}}\";\n"
	"                }\n"
	"                $value = str_replace($replace, $vars, $value);\n"
	"            }\n"
	"\n"
	"        }\n"
	"\n"
	"        return $value;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 自动侦测设置获取语言选择\n"
	"     * @access public\n"
	"     * @return string\n"
	"     */\n"
	"    public static function detect()\n"
	"    {\n"
	"        $langSet = \'\';\n"
	"\n"
	"        if (isset($_GET[self::$langDetectVar])) {\n"
	"            // url 中设置了语言变量\n"
	"            $langSet = strtolower($_GET[self::$langDetectVar]);\n"
	"        } elseif (isset($_COOKIE[self::$langCookieVar])) {\n"
	"            // Cookie 中设置了语言变量\n"
	"            $langSet = strtolower($_COOKIE[self::$langCookieVar]);\n"
	"        } elseif (isset($_SERVER[\'HTTP_ACCEPT_LANGUAGE\'])) {\n"
	"            // 自动侦测浏览器语言\n"
	"            preg_match(\'/^([a-z\\d\\-]+)/i\', $_SERVER[\'HTTP_ACCEPT_LANGUAGE\'], $matches);\n"
	"            $langSet     = strtolower($matches[1]);\n"
	"            $acceptLangs = Config::get(\'header_accept_lang\');\n"
	"\n"
	"            if (isset($acceptLangs[$langSet])) {\n"
	"                $langSet = $acceptLangs[$langSet];\n"
	"            } elseif (isset(self::$acceptLanguage[$langSet])) {\n"
	"                $langSet = self::$acceptLanguage[$langSet];\n"
	"            }\n"
	"        }\n"
	"\n"
	"        // 合法的语言\n"
	"        if (empty(self::$allowLangList) || in_array($langSet, self::$allowLangList)) {\n"
	"            self::$range = $langSet ?: self::$range;\n"
	"        }\n"
	"\n"
	"        return self::$range;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置语言自动侦测的变量\n"
	"     * @access public\n"
	"     * @param  string $var 变量名称\n"
	"     * @return void\n"
	"     */\n"
	"    public static function setLangDetectVar($var)\n"
	"    {\n"
	"        self::$langDetectVar = $var;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置语言的 cookie 保存变量\n"
	"     * @access public\n"
	"     * @param  string $var 变量名称\n"
	"     * @return void\n"
	"     */\n"
	"    public static function setLangCookieVar($var)\n"
	"    {\n"
	"        self::$langCookieVar = $var;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置语言的 cookie 的过期时间\n"
	"     * @access public\n"
	"     * @param  string $expire 过期时间\n"
	"     * @return void\n"
	"     */\n"
	"    public static function setLangCookieExpire($expire)\n"
	"    {\n"
	"        self::$langCookieExpire = $expire;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 设置允许的语言列表\n"
	"     * @access public\n"
	"     * @param  array $list 语言列表\n"
	"     * @return void\n"
	"     */\n"
	"    public static function setAllowLangList($list)\n"
	"    {\n"
	"        self::$allowLangList = $list;\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif